# 打开文件
# import json
# import os
#
# f = open('day08.txt', 'r', encoding='utf8')

# 读取文件,不填值默认为为全部
# result = f.read(20);
#
# print(result)

# str_list=(f.readlines())//['www.zhangwangyan.com\n', 'blog.zhagnwangyan.com']
# print(str_list)

# while True:
#     j=f.readline();
#     print(j)
#     if j=='':
#         break
#
#
# #最后要记得关闭文件
# f.close()


"""
总结 open   read(20) readlines() readline()
    with open  python自动关闭资源
"""
import json

# with open('day08.txt', 'r', encoding='utf8') as f:
#     str1 = f.read(5)
#     print(str1)
#
# verify_close = input("请输入")

"""
# 你需要编写一个 Python 脚本，读取文件内容并计算出所有学生的平均成绩


# 通过在with open的语句块中对文件进行操作
# 可以在操作完成后自动关闭close文件，避免遗忘掉close方法
# with open("python.txt", "r") as f:
#     f.readlines()

"""
# with open('grades.txt', 'r', encoding='utf8') as f:
#     while True:
#         line = f.readline().strip()  # 不能使用list转换 ['A', 'l', 'i', 'c', 'e', ',', '8', '5']
#         list1 = line.split(',')
#         print(list(line))
#         print(type(line))
#         if (line == ''):
#             break
"""
itheima itcast python
itheima python itcast
beijing shanghai itheima
shenzhen guangzhou itheima
wuhan hangzhou itheima
zhengzhou bigdata itheima
"""
# 需求: itheima字符串出现的次数..
# with open('word.txt','r',encoding='utf-8')as file:
#     lines = file.readlines() # ['itheima itcast python\n', 'itheima python itcast\n'...]
#     counts = 0
#     for line in lines:
#         counts += line.count('itheima')# 字符串的count功能可以求出小串在大串中出现的次数.
#     print(f"itheima字符串出现的次数:{counts}")


# 代码写入
# with open('word.txt','w',encoding='utf-8')as f:
#     f.write('张王岩,记得创建一个记忆卡片')
#     f.flush()
#     f.write('天王盖地虎啊')
# with open('word.txt','a',encoding='utf-8')as f:
#     f.write("这是追加的内容")

# 代码读入 写入
# f1=open('word.txt',encoding='utf-8')
# f2=open('自动生成.txt','w',encoding='utf-8')  #这里记得要写
#
# # list=f1.readlines();
# for i in f1:
#     if i.count('张王岩')>0:
#         f2.write(i)
# f1.close()
# f2.close()


# os 模块代码 了解
# os.rename('word.txt','裕王')
# os.mkdir('A建材老王')
# os.rmdir('A建材老王')

data = {'name': '张三', 'password': 123456}

json.dump(data, open('day08.txt', 'w', encoding='utf8'))
json.load('day08.txt')
